package com.manlost.backoffice.controller.baby;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.manlost.upload.AblumUploadService;
import com.manlost.upload.UploadServiceLocator;
import com.manlost.upload.model.constant.AblumConstant;
import com.manlost.upload.model.dataobject.AblumFolder;
import com.manlost.upload.util.AblumFolderUtil;

/**
 * 类BabyManageController.java的实现描述：TODO 类实现描述
 * 
 * @author xiaochuan.luxc 2012-5-2 下午7:49:31
 */
@Controller
@SuppressWarnings({ "rawtypes", "unchecked" })
public class BabyManageController {

    private static final String RESULT_KEY         = "result";
    private AblumUploadService  ablumUploadService = UploadServiceLocator.getAblumUploadService();

    @RequestMapping(value = "/baby/localAblumManage.htm", method = RequestMethod.GET)
    public String localAblumManage(Map model) {
        List<AblumFolder> ablumFolders = AblumFolderUtil.listAblumFolders(AblumConstant.defaultPath);
        model.put("defaultPath", AblumConstant.defaultPath);
        model.put("ablumFolders", ablumFolders);
        ablumUploadService.uploadLocalAblum("");
        return "baby/localAblumManage";
    }

    @RequestMapping(value = "/baby/uploadAjax.htm", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> uploadAjax(Map model, String ablumPath) {
        Map<String, Object> result = new HashMap<String, Object>();
        if (StringUtils.isBlank(ablumPath)) {
            result.put(RESULT_KEY, "ablumPath is empty!");
        }
        ablumUploadService.uploadLocalAblum(ablumPath);
        result.put(RESULT_KEY, ablumPath + " upload success");
        return result;
    }
}
